<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false"  class="wrap">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
	    <div class="bt">人事添加</div>
	    <el-form label-width="100px" class="form">
 			<el-form-item label="中文名">
 				<el-input v-model="vzwm"  placeholder="请输入中文名" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="英文名">
 				<el-input v-model="vywm"  placeholder="请输入英文名" class="select-block"></el-input>
 			</el-form-item>
			<el-form-item label="性别">
                   <el-select v-model="vxb" placeholder="请选择性别"  class="select-block">
  					  <el-option label="男" value="男"></el-option>
  					  <el-option label="女" value="女"></el-option>
  			      </el-select>
 			</el-form-item>
		    <el-form-item label="电话">
 				<input v-model="vdh" type="number" @blur='yz' placeholder="请输入电话号"   class="input1" style="width: 85%;float: left;text-align: left;">
 		    </el-form-item>
 		    <el-form-item label="身份证(护照)">
 		    	<!--<input v-model="vsfz" type="number" @blur='sfyz'  placeholder="请输入身份证"  class="input1" style="width: 85%;float: left;text-align: left;">-->
 				<el-input v-model="vsfz"  placeholder="请输入" class="select-block"></el-input>
 		    </el-form-item>
        <el-form-item label="职位">
  			       <el-select v-model="vlstype" class="select-block"  >
					<el-option :label="v.mc" :value="v.lstype" v-for="v in comboxlist"></el-option>
		    </el-select>
 			</el-form-item>
		</el-form>
        <div style="text-align: center;">
		<el-button type="primary" class="submit" :disabled='tj' @click="submit">添加</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		</div>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
//				vgh: '',
//				vmm: '',
				vdh: '',
				tj:false,
//				vtx: '',
				vxb: '女',
				vsfz:'',
				vzwm: '',
				vywm: '',
//				vbjs: '',
				vlstype:this.params,
//				xzls:'',
				ghList:'',
				xzlsList: [],
				comboxlist:[]
			}
		},
		created() {
			this.getxzlsList();
			this.getcomlist();
		},
		methods: {
			yz(){
				if(!(/^1\d{10}$/.test(this.vdh))){
						this.$message.error('输入手机号不正确!');
						this.tj=true;
					}
				else{
					this.tj=false;
				}
			},
			sfyz(){
				if(!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(this.vsfz))){
						this.$message.error('输入身份证号不正确！');
					}
			},
			 getcomlist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
				var params3 = qs.stringify({
					yhid:logininfo.id,
					xxid:logininfo.xxid,
				});
					this.searchLoading = true;
					this.axios.post(this.$store.state.api + 'ls/lstypelist',params3)
					.then( res => {
							let data = res.data.data;
							let list = data.list;
							this.comboxlist=list;
					}).catch( res => {
							this.searchLoading = false;
					})
			},
			getxzlsList () {
				var logininfo = JSON.parse(localStorage.logininfo);
                var params2 = qs.stringify({
                  xxid:logininfo.xxid,
 							 yhid: logininfo.id,
							 xxid:logininfo.xxid
               })
                 this.axios.post(this.$store.state.api + 'ls/xzxzls',  params2 )
                 .then(res => {
							this.xzlsList = res.data.data;
                 }).catch(res => {
				})
			},
			submit() {
				//检测
				this.$store.state.loading = true;
			    if(!this.vzwm) {
					this.$message.warning('请填写中文名');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vywm) {
					this.$message.warning('请填写英文名');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vdh) {
					this.$message.warning('请填写电话');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vsfz) {
					this.$message.warning('请填写身份证');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vlstype) {
					this.$message.warning('请填写职位');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
//					xzid:this.xzls,
//					gh: this.vgh,
//					mm: this.vmm,
					dh: this.vdh,
		//			tx: this.vtx,
					xb: this.vxb,
					zwm: this.vzwm,
					ywm: this.vywm,
					sfz: this.vsfz,
//					bjs: this.vbjs,
					lstype: this.vlstype,
					yhid:logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'ls/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
						}
					}).catch(res => {
						this.$message.error("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.el-dialog--small{
			width: 200px;
		}
		.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
	     .select-block {
 		display: block;
 			width: 85%;
 	}
	.form {
		text-align: center;
		margin-top:20px;

	}
	.input {
		display: inline-block;
		}
		.input-block {
			margin-bottom: 20px;
			text-align: center;
			.input {
				width: 180px;
				display: inline-block;
			}

		}
	     .select-block {
 		display: block;
 			width: 85%;
 	}
	.form {
		text-align: center;
		margin-top:20px;

	}
	.input {
		display: inline-block;

			}
		.submit {
			width: 120px;
		}

	}
	.input1{
		    width: 300px;
			height: 30px;
			text-align: left;
			/*outline: none;*/
			border: 1px solid #CCCCCC;
			background: none;
			border-radius: 5px;
			// margin-left: 20%;
			text-align: center;
	}
	input::-webkit-outer-spin-button,
	input::-webkit-inner-spin-button{
   -webkit-appearance: none !important;
    }
    input[type="number"]{-moz-appearance:textfield;}
</style>
